package modele;

import java.util.Collection;

public class Pays {

    private Collection<Dep> lesDeps;
    private Collection<Spe> lesSpec;

    public Pays() {
        lesDeps = DAO.getLesDeps();
        lesSpec = DAO.getLesSpec();
        Collection <Med> lesMeds = DAO.getLesMeds();
        assocMedecins(lesMeds);
    }

    public Collection<Dep> getLesDeps() {
        return lesDeps;
    }

    public Collection<Spe> getLesSpec() {
        return lesSpec;
    }

    public Dep getLeDep(String num) {
        for (Dep leDep : lesDeps) {
            if (num.equals(leDep.getNum())) {
                return leDep;
            }
        }
        return null;
    }

    private void assocMedecins(Collection<Med> lesMeds) {
        for (Med unMed : lesMeds) {
            getLeDep(unMed.getDep()).addUnMed(unMed);
            Spe uneSpe = getLaSpe(unMed.getSpe());
            if (uneSpe != null) {
                uneSpe.addUnMed(unMed);
            }
        }
    }

    public Spe getLaSpe(String spe) {
        for (Spe laSpe : lesSpec) {
            if (laSpe.getNom().equals(spe)) {
                return laSpe;
            }
        }
        return null;
        
    }
}